using System;
using System.Collections.Generic;
using System.Collections;

using FinancialAnalyzer.ToolClasses;

namespace FinancialAnalyzer.MoneyFlow 
{
    public class MoneyFlowMembers : IList<MoneyFlowItem>
    {
        private List<MoneyFlowItem> _memberList;

        public MoneyFlowMembers()
        {
            _memberList = new List<MoneyFlowItem>();
        }

        public MoneyFlowMembers(List<MoneyFlowItem> ilist)
        {
            _memberList = new List<MoneyFlowItem>(ilist);
        }

        public List<MoneyFlowItem> getList()
        {
            return _memberList;
        }

        public int IndexOf(String name, EFlowDirection flowDir)
        {
            for (int i = 0; i < _memberList.Count; i++)
			{
                if(_memberList[i].Name.Equals(name) && _memberList[i].FlowDirection == flowDir)
                {
                    return i;
                }			    
			}
            return -1;
        }

        #region IList<MoneyFlowItem> Member

        public void Add(String name, EFlowDirection direction,Boolean IsFixedMonthly, Double MonthlyValue, Double ValueValency)
        {
            _memberList.Add(new MoneyFlowItem(name, direction, IsFixedMonthly, MonthlyValue, ValueValency));
        }


        public int IndexOf(MoneyFlowItem item)
        {
            return _memberList.IndexOf(item);
        }

        public void Insert(int index, MoneyFlowItem item)
        {
            _memberList.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            _memberList.RemoveAt(index);
        }

        public MoneyFlowItem this[int index]
        {
            get
            {
                return _memberList[index]; 
            }
            set
            {
                _memberList[index] = value; 
            }
        }

        #endregion

        #region ICollection<MoneyFlowItem> Member

        public void Add(MoneyFlowItem item)
        {
            _memberList.Add(item);
        }

        public void Clear()
        {
            _memberList.Clear();
        }

        public bool Contains(MoneyFlowItem item)
        {
            return _memberList.Contains(item);
        }

        public void CopyTo(MoneyFlowItem[] array, int arrayIndex)
        {
            _memberList.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return _memberList.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(MoneyFlowItem item)
        {
            return _memberList.Remove(item);
        }

        #endregion

        #region IEnumerable<MoneyFlowItem> Member

        public IEnumerator<MoneyFlowItem> GetEnumerator()
        {
            return _memberList.GetEnumerator();
        }

        #endregion

        #region IEnumerable Member

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _memberList.GetEnumerator();
        }

        #endregion

    }
}
